﻿/* Author: Tomer Paz
   games.com
   2007
*/

/* network Binary Socket wrapper */

package monopoly.IFS.Net {
	
	import monopoly.IFS.utils.encryption.MD5;
	import flash.net.Socket;
	import flash.utils.ByteArray;
	import flash.errors.IOError;
	import flash.errors.EOFError;
	import flash.events.IOErrorEvent;
	import flash.utils.Endian;

	public class SocketW extends Socket
		{
		//private var _storeByteArray:ByteArray;
		
		public function SocketW(EndianType:String)
			{
			//_storeByteArray = new ByteArray( );
			super( );		// redundant since called automatically, but just for the purpose of clearity
			super.endian = EndianType;
			}
		
		/* some socket read/write function wrappers */
		
		// atomic writeLine 
		public function writeLine(ByteArr:ByteArray):void
			{
			ByteArr.writeUTFBytes("\n");
			
			try {
				this.writeBytes(ByteArr);
	    		this.flush();
				}
			catch (error:IOError)
				{
				trace("Error on ServerSocket.writeBytes or flush: " + error);
				}
			}
			
		// read Line wrapper
		public function readBytesW():ByteArray
			{
			var BytesAvailable:uint = this.bytesAvailable;
			var ByteArr:ByteArray = new ByteArray();

			try {
				super.readBytes(ByteArr, 0, BytesAvailable);
				}
			catch (error:IOError)
				{
				trace("Error on ServerSocket.readBytes: " + error);
				return null;
				}
				
			return ByteArr;
			}
		}
}